var gulp = require('gulp');
var exec = require('child_process').exec;

gulp.task('install', function () {
  exec("yarn install:build");
});

gulp.task('mobile', function () {
  exec("yarn mobile:build");
});

gulp.task('web', function () {
  exec("yarn web:build");
});

const build = function () {
  return new Promise((resover, reject) => {
    exec('sh build.sh', function () {
      resover();
    });
  });
}

var watcher = gulp.watch('./src/**/*', gulp.series(build, function () {
  console.log('build success');
}));
var installWatcher = gulp.watch('./projects/install/src/**/*', gulp.series('install', function () {
  console.log('install success');
}));
var mobileWatcher = gulp.watch('./projects/mobile/src/**/*', gulp.series('mobile', function () {
  console.log('mobile success');
}));
var webWatcher = gulp.watch('./projects/web/src/**/*', gulp.series('web', function () {
  console.log('web success');
}));

gulp.task('default', gulp.series(build, function () {
  watcher.on('change', function () {
    console.log('server change');
  });
}));

gulp.task('install', function () {
  installWatcher.on('change', function () {
    console.log('install change');
  });
});

gulp.task('mobile', function () {
  mobileWatcher.on('change', function () {
    console.log('mobile change');
  });
});

gulp.task('web', function () {
  webWatcher.on('change', function () {
    console.log('web change');
  });
});
